<%@ page import="java.sql.Statement" import="java.sql.ResultSet" import="java.sql.Connection" %>
<%@page import="connection.DBConnection"%>
<%@page import="java.util.*" %>
<%@page import="java.text.SimpleDateFormat" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Bank Date Report</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>

<%-- <script>
	$("table tr td:nth-child(2)").each(function () 
	{ });
</script>
--%>
<%--
<script>

function ReadBankDate()
{
	var table = $("bankreport"); // Make this more accurate if there are multiple tables on the page
	var rows = table.find("tr");  // Will find too much if there are <tr> tags nested in each other

	for (var i=0; i=rows.length; ++i) 
	{
	  var cells = rows.eq(i).find("td");
	  var values = [cells.eq(0).text(), cells.eq(1).text()];
	  
	  alert(values);
	}	
}

// $("tr td:nth-child(1), tr td:nth-child(2)").css('color', 'red');
</script>
--%>

</head>
<body>
<h2 align="center"> Bank Date Report</h2>
<form name="bankdatereport" method="get" action="BankDateReportServlet">

  <%
        String exportToExcel = request.getParameter("exportToExcel");
        if (exportToExcel != null && exportToExcel.toString().equalsIgnoreCase("YES")) 
        {
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-Disposition", "inline; filename=" + "BankDateReport.xls");
 
        }
    %>

<table id="bankreport" border=1 align="center"> 

<tr>
		<th> Bank Name </th>
		<th> Bank Date </th>
		<th> Receipts Entry number </th>
		<th> Date </th>
		<th> Cheque Number </th>
		<th> Account Name </th>
		<th> Amount </th>
		<th> Narration </th>
</tr>
<tbody>
		<%  DBConnection dbc=new DBConnection();
			Connection con=dbc.getNewConnection();
			Statement st = null;
			ResultSet rs = null;
			
			double ramount6=0.0,ramount8=0.0;
			double rv6=0.0,rv8=0.0;
			
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select * from ReceiptsVoucher2 where status=1 And bname <> 'Cash' "); %>
	        	
       		 <%  while(rs.next()){ %>
<tr>
            		<td><%= rs.getString(1)%></td>
            		<%-- <td><div contenteditable> </div>  </td> --%>
            		
            		<td> <input type="text" name="rbankdate"> </td>
            		
            		<td><%= rs.getString(2)%></td>
            		
            		<% String rvdate= rs.getString(3); 
           	    		 SimpleDateFormat fromsql = new SimpleDateFormat("yyyy-MM-dd");
        				 SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
        		 		 String newdate =formatter.format(fromsql.parse(rvdate));
            		%>
            		<td><%=newdate %></td>
            		
            		<td><%= rs.getString(4)%></td>
            		<td><%= rs.getString(5)%></td>
            		
            		<% rv6= rs.getDouble(6); %>
            		<td><%=rv6%></td>
            		<td><%= rs.getString(7)%></td>
            		
</tr>
        		<% 	ramount6=ramount6+rv6;
        			ramount8=ramount8+rv8;
        			} %>
  
	 		<% }
			catch(Exception e){} %>

		<%  			
			double pamount6=0.0,pamount8=0.0;
			double pv6=0.0,pv8=0.0;
			
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select * from PaymentVoucher2 where status=1 And bname <> 'Cash' "); %>
	        	
       		 <%  while(rs.next()){ %>
<tr>
            		<td><%= rs.getString(1)%></td>
            		<%-- <td><div contenteditable> </div>  </td> --%>
            		
            		<td> <input type="text" name="pbankdate"> </td>
            		
            		<td><%= rs.getString(2)%></td>
            		
            		<% String rvdate= rs.getString(3); 
           	    		 SimpleDateFormat fromsql = new SimpleDateFormat("yyyy-MM-dd");
        				 SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
        		 		 String newdate =formatter.format(fromsql.parse(rvdate));
            		%>
            		<td><%=newdate %></td>
            		
            		<td><%= rs.getString(4)%></td>
            		<td><%= rs.getString(5)%></td>
            		
            		<% pv6= rs.getDouble(6); %>
            		<td><%=pv6%></td>
            		<td><%= rs.getString(7)%></td>
            		
</tr>
        		<% 	pamount6=pamount6+rv6;
        			pamount8=pamount8+rv8;
        			} %>
  
	 		<% }
			catch(Exception e){} %>

</tbody>		
<tr>
	<td> <b> Total </b></td>
	<td> </td>
	<td> </td>
	<td> </td>
	<td> </td>
	<td> </td>
	<td> <%=ramount6+pamount6 %></td>
	<td> </td>
</tr>			
			
</table>
<br>
	<input type="Submit" value="Submit" name="bankbutton" id="bankbutton">
	
<br><br> 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <%
        if (exportToExcel == null) {
    %>
    <a href="BankDateReport.jsp?exportToExcel=YES">Export to Excel</a>
    <%
        }
    %>
</form>
 
 <%--
 <script >
 
 $(function(){
   $('#bankbutton').click(function () 
  	{
	   $('tr').each(function()
	   {
		  a = $(this).children('td:eq(0)').text();
		  b = $(this).children('td:eq(1)').text();		   

		   alert("Bank Name  "+a+"  Bank Date"+ b);
	   });
	   
	});
 });
 
</script>
--%>
</body>
</html>